<template>
  <el-form label-width="80px" :model="form" :rules="rules" ref="form">
    <el-form-item label="用户名" prop="name">
      <el-input v-model="user.name" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login">登陆</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  data() {
    return {
      labelPosition: "right",
      form: {
        name: "",
        password: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
           {
            min:6,
            max:20,
            message: "请输入正确的用户名",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密吗",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    login() {
      console.log(this.form.name)
      this.$refs.form.validate((valid) => {
        if (valid) {
          alert("submit");
        } else {
          return false;
        }
      });
    },
  },
};
</script>
<style>
.el-form{
    max-width: 450px;
    margin:50px auto 10px;
}
</style>